// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const dictDataRequest = {
    // dict请求的基本url
    BASE_URL : confing.SYS_URL + "/dictData",
	/**
	 * 保存字典信息
	 * @param {*} dict 
	 * @param {*} callback 
	 */
	save(dictData,callback){
	    if(dictData){
	        request.post(this.BASE_URL + "/save",dictData,callback);
	    }
	},
	/**
	 * 删除字典
	 * @param {*} dictId 
	 * @param {*} callback 
	 */
	delete(dataId,callback){
	    let url = this.BASE_URL + "/delete?dataId=" + dataId;
	    request.delete(url,callback);
	},
	/**
	 * 批量删除字典
	 * @param {*} dictIds 
	 * @param {*} callback 
	 */
	deletes(dataIds,callback){
	    let url = this.BASE_URL + "/deletes?t=1";
	    dataIds.forEach(element => {
	        url += "&dataId=" + element;
	    });
	    request.delete(url,callback)
	},
	edit(dictData,callback){
	    console.log(dictData);
	    let url = this.BASE_URL + "/update";
	    if(dictData != undefined && dictData.dataId != undefined){
	        request.put(url,dictData,callback)
	    }
	},
	selectById(dataId,callback){
	    if(dataId){
	        // 准备url
	        let url = this.BASE_URL + "/selectById?dataId=" + dataId;
	        request.get(url,callback);
	    }
	    // 如果没有userId，不做任何处理
	},
    /**
     * 通过字典编号查询字典数据
     * @param {*} dictId 
     * @param {*} callback 
     */
    list(dictId,callback){
        request.get(this.BASE_URL + "/list?dictId=" + dictId,callback);
    },
}

// 将dictRequest暴漏出去
export default dictDataRequest;